package com.intellagric.controller.module.trace_invest;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.InvestVo;
import com.intellagric.pojo.TraceInvest;
import com.intellagric.service.traceability.trace_invest.InvestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/9
 * @DESC： 投入品信息管理
 */
@Controller
public class InvestController {

    @Autowired
    private InvestService investService;

    /**
     * 添加投入品信息
     * @Param invest
     * @return ResponseMessage
     */
    @RequestMapping("/invest/add")
    @ResponseBody
    public ResponseMessage add(TraceInvest invest) {
        invest.setId(UUID.randomUUID().toString().replaceAll("-",""));
        invest.setCreateDate(new Date());
        invest.setUpdateDate(new Date());
        return investService.addInvest(invest);
    }


    /**
     * 删除投入品信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/invest/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return investService.deleteInvest(id);
    }

    /**
     * 修改投入品信息
     * @Param invest
     * @return ResponseMessage
     */
    @RequestMapping("/invest/edit")
    @ResponseBody
    public ResponseMessage edit(TraceInvest invest) {
        invest.setUpdateDate(new Date());
        return investService.editInvest(invest);
    }

    /**
     * 查询投入品信息
     * @return Object
     */
    @RequestMapping("/invest/{id}")
    @ResponseBody
    public TraceInvest get(@PathVariable String id) {
        return investService.getInvestById(id);
    }

    /**
     * 查询投入品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return investService.getInvestList();
    }

    /**
     * 分页查询投入品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return investService.getInvestPage(page, limit);
    }

    /**
     * 分页查询投入品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/pageByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,String createBy) {
        return investService.getInvestPage(page, limit,createBy);
    }
    /**
     * 查找byvo
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/query")
    @ResponseBody
    public LayuiDataGridResult query(int page, int limit, InvestVo vo) {
        return investService.queryByVo(page, limit,vo);
    }

}
